package com.bl.feignclient;

import com.bl.domain.User;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class UserFallbackFactory implements FallbackFactory<UserFeignClient> {


  // 创建降级类
   @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient() {
            // 降级方法
            @Override
            public User geById(Long id) {
                return new User(-1L,"熔断","熔断触发");
            }

            @Override
            public List<User> findAll() {
                List<User> users = new ArrayList<>();

                users.add(new User(-1L,"熔断","熔断触发"));
                return users;
            }
        };
    }
}
